import requests
import ssl

from tqdm import tqdm
from lxml import etree
import argparse
# requests.packages.urllib3.disable_warnings()
# ssl._create_default_https_context = ssl._create_unverified_context()
# parser=argparse.ArgumentParser(description="获取河北经贸大学指定学号座位")
# parser.add_argument('-p',dest='precode',type=str,required=True,help="指定要查找范围指定长度")
# parser.add_argument('-s',dest='start',type=int,required=True,help="指定范围起始范围")
# parser.add_argument('-e',dest='end',type=int,required=True,help="指定范围结束范围")
# parser.add_argument('-c',dest='count',type=int,required=True,help="指定变动的数字位数,不够在前面自动补零")
# args=parser.parse_args()
list=[]
def getseat(precode,begin,to,count):
    for i in tqdm(range(begin,to+1)):
        id = str(i).rjust(count, '0')
        headers = {
            "Cookie": "Friends_where_frienddent_id=WechatTSG="+precode + id + "; Friends_where_friendname=WechatTSG=%e4%ba%8e%e6%b4%aa%e6%9c%8b; UserIdentID=WechatTSG=A168B653A46EAA53693046612E2E9EBE; UserOpenID=WechatTSG=odsLhshCyIPTt9jdPoQHcXuUPT3M;"
        }
        url = 'https://libapp.hueb.edu.cn/Seat/friends/friendSeat.aspx'
        res = requests.get(url=url, verify=False, headers=headers)
        element = etree.HTML(res.content, parser=etree.HTMLParser(encoding='utf-8'))
        if (element.xpath("//title/text()")[0].strip() == "座位精灵"):
            obj=(precode+str(id),element.xpath("//input[@id='lblRoomName']/@value")[0],element.xpath("//input[@id='lblSeatNo']/@value")[0],element.xpath("//input[@id='lblBeginTime']/@value")[0])
            print(" "+obj[0],end=' ')
            print(obj[1], end=' ')
            print(obj[2], end=' ')
            print(obj[3])
            list.append(obj)
        else:
            pass
    for item in list:
        print(item)
            #print(precode+id,end=' ')
